package com.ljh.myaiagent.controller;

import com.ljh.myaiagent.common.BaseResponse;
import com.ljh.myaiagent.common.ResultUtils;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/health")
public class HealthController {

    private final JdbcTemplate primaryJdbcTemplate;
    private final JdbcTemplate vectorJdbcTemplate;

    public HealthController(
            @Qualifier("primaryJdbcTemplate") JdbcTemplate primaryJdbcTemplate,
            @Qualifier("vectorJdbcTemplate") JdbcTemplate vectorJdbcTemplate
    ) {
        this.primaryJdbcTemplate = primaryJdbcTemplate;
        this.vectorJdbcTemplate = vectorJdbcTemplate;
    }


    @GetMapping
    public BaseResponse<String> healthCheck(){
        return ResultUtils.success("ok");
    }

    @GetMapping("/mysql")
    public String mysqlHealth() {
        Integer result = primaryJdbcTemplate.queryForObject("SELECT 1", Integer.class);
        return String.valueOf(result);
    }

    @GetMapping("/postgres")
    public String postgresHealth() {
        Integer result = vectorJdbcTemplate.queryForObject("SELECT 1", Integer.class);
        return String.valueOf(result);
    }
    
}
